
#Title[]
#Text[]
#Image[.]
#BackGround[User]
#Player[]
#ScriptVersion[2]
script_enemy_main {

let csd = GetCurrentScriptDirectory;
let imgShot=csd ~ "..\img/shot_all.png";

let imgCircle=csd ~ "..\img/circle.png";
let imgPlain=csd ~ "..\img/plain.png";
let imgWater=csd ~ "..\img/water.png";
let imgWood=csd ~ "..\img/wood.png";
let imgMagma=csd ~ "..\img/magma.png";
let imgGoal=csd ~ "..\img/goal.png";
let imgPlayer=csd ~ "..\img/marisa.png";
let imgAllow1=csd ~ "..\img/allow1.png";
let imgAllow2=csd ~ "..\img/allow2.png";
let imgAllow3=csd ~ "..\img/allow3.png";
let imgAllow4=csd ~ "..\img/allow4.png";
let imgBlock=csd ~ "..\img/block.png";
let imgFloor=csd ~ "..\img/floor.png";
let imgAnti=csd ~ "..\img/anti.png";

SetRateScoreSystemEnable(false);

let PlayerPosition=[];
let MagicStonePosition=[];
let PlayerPositionInt=[];
let MagicStonePositionInt=[];
let GoalPosition=[];
let PedestalPosition=[]; 
let Graund=[];
let Object=[];

let PlayerDirection=90;
let ObjectMove=[];
let ReinforceMagicBall=[];

let PlayerPositionNum=0;
let MagicStonePositionNum=0;
let GoalPositionNum=0;

let ExplodeObjectMoveRight=[];
let ExplodeObjectMoveLeft=[];
let ExplodeObjectMoveUp=[];
let ExplodeObjectMoveDown=[];

let startcount=0;

    @Initialize {
	Graund=GetCommonDataDefault("Graund",[]);
	Object=GetCommonDataDefault("Object",[]);
	PlayerPosition=GetCommonDataDefault("PlayerPosition",[]);
	MagicStonePosition=GetCommonDataDefault("MagicStonePosition",[]);
	GoalPosition=GetCommonDataDefault("GoalPosition",[]);
	PedestalPosition=GetCommonDataDefault("PedestalPosition",[]);
	PlayerPositionInt=PlayerPosition;
	MagicStonePositionInt=MagicStonePosition;

	SetCommonData("StagePlaying",true);
	SetCommonData("StageClear",false);
	MagicCircle(0);
        SetLife(3500);
        LoadGraphic(imgShot);
        LoadGraphic(imgCircle);
        LoadGraphic(imgPlain);
        LoadGraphic(imgWater);
        LoadGraphic(imgWood);
        LoadGraphic(imgMagma);
        LoadGraphic(imgGoal);
        LoadGraphic(imgPlayer);
        LoadGraphic(imgAllow1);
        LoadGraphic(imgAllow2);
        LoadGraphic(imgAllow3);
        LoadGraphic(imgAllow4);
        LoadGraphic(imgBlock);
        LoadGraphic(imgFloor);
        LoadGraphic(imgAnti);
        TMainGrobal;
    }

    @MainLoop {

	PlayerPositionNum=round(PlayerPosition[0]+PlayerPosition[1]*13);
	MagicStonePositionNum=round(MagicStonePosition[0]+MagicStonePosition[1]*13);
	GoalPositionNum=round(GoalPosition[0]+GoalPosition[1]*13);
	if(round(PedestalPosition[0])==round(MagicStonePositionInt[0]) && round(PedestalPosition[1])==round(MagicStonePositionInt[1]))
	{
	if(round(GoalPosition[0])==round(PlayerPositionInt[0]) && round(GoalPosition[1])==round(PlayerPositionInt[1]))
	{
		SetCommonData("StagePlaying",false);
		SetCommonData("StageClear",true);
	}
	}

	if(startcount==-1)
	{
	if(GetKeyState(VK_SLOWMOVE)==KEY_FREE && GetCommonData("StageClear")==false)
	{
	AddScore(1);
        yield;
	if(GetKeyState(VK_USER)==KEY_PUSH || GetKeyState(VK_USER)==KEY_HOLD)
	{
		SetCommonData("StagePlaying",false);
		SetCommonData("StageFailed",true);
	}
/*
	if(GetKeyState(VK_SKIP)==KEY_PUSH || GetKeyState(VK_SKIP)==KEY_HOLD)
	{
		AddScore(1);
		yield;
	}
*/
	}
	}
	if(startcount==0)
	{
	yield;
	startcount+=1;
	}
	if(GetKeyState(VK_UP)!=KEY_FREE || GetKeyState(VK_DOWN)!=KEY_FREE || GetKeyState(VK_LEFT)!=KEY_FREE || GetKeyState(VK_RIGHT)!=KEY_FREE)
	{
		startcount=-1;
	}
    }

    @DrawLoop {
	//DrawText(trunc(PlayerPosition[0]+0.1),120,382,12,255);//NԂ̕\
	//DrawText(MagicStonePositionNum,200,382,12,255);//NԂ̕\
	//DrawText(Graund[round(PlayerPosition[0]+PlayerPosition[1]*11)+1],280,382,12,255);//NԂ̕\

    }

    @Finalize {
    }

    // C^XN
task TMainGrobal
{
	yield;
	DisPlayPlayer;
	DisPlayMagicStone;
	DisPlayGoal;
	DisPlayPedestal;
	PlayerMove;
	GraundDraw;
	StageObject;
}


#include_function ".\..\txt/data.txt"

}
